<template>
    <div>
        <input v-model="newActivity.info" placeholder="请输入内容">
        <button @click="addActivity">确定</button>
        <ul>
            <li v-for="(text, index) in list" :key="index" @click="selectActivity(index)">{{ text.info }}</li>
        </ul>
    </div>
</template>
<script>
export default {
    name: 'HomeList',
    data() {
        return {
            list: JSON.parse(localStorage.getItem('activityList')) ||
                [{ info: " 吃饭" }, { info: "睡觉", }, { info: "打豆豆" }],
            newActivity: { info: '' }
        }
    },
    methods: {
        addActivity() {
            this.list.push({ ...this.newActivity });
            this.newActivity.info = "";
            localStorage.setItem('activityList', JSON.stringify(this.list));
        },
        selectActivity(index) {

            this.$router.push({
                path: '/home/choice',
                query: {
                    title: this.list[index].info
                }
            })
        }
    },
}
</script>
